package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationMemberDto;
import com.zzyl.nursing.vo.ReservationMemberVo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;


@Mapper
public interface ReservationMemberMapper extends BaseMapper<Reservation> {
    @Update("update zzyl.reservation set status = 2 where id = #{id}")
    void cancelReservation(Long id);

    /**
     * 查询预约登记列表
     *
     * @param reservation 预约登记
     * @return 预约登记集合
     */
    List<Reservation> selectReservationList(@Param("reservation")Reservation reservation,@Param("fid")Long id);

    @Select("select count(*) from zzyl.reservation where reservation.update_by = #{id} and status = 2 and update_time >= CURDATE() \n" +
            "AND update_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY) ")
    Long findReservationList(Long id);


    List<ReservationMemberVo> countByTime(List<LocalDateTime> time);

    @Select("select count(*) from zzyl.reservation where mobile = #{mobile} and time = #{time}")
    Long isAppointment(@Param("mobile") String mobile,@Param("time") LocalDateTime time);

    @Select("select count(*) from zzyl.elder where name = #{visitor} and status = 0")
    Long isStatus(@Param("visitor") String visitor);

    @Insert("insert into zzyl.reservation(name, mobile, time, visitor, type, status, create_time, update_time, create_by, update_by, remark)" +
            "values(#{name},#{mobile}, #{time}, #{visitor}, #{type},#{status}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{remark})")
    void addReservationMember(ReservationMemberDto reservationMemberDto);
}
